#include "tableau.h"
#include <iostream>

Tableau::Tableau(unsigned int max)
{
	taille=max;
	nb=0;
	tab=new long[taille];
}
Tableau::~Tableau()
{
	delete[] tab;
}
Tableau::Tableau(const Tableau& T)
{
	taille=T.taille;
	nb=T.nb;
	tab= new long[taille];
	for(unsigned int i=0;i<nb;i++)
	{
		tab[i]=T.tab[i];
	}
}

long& Tableau::operator[](unsigned int i)
{
	return tab[i];
}
void Tableau::ajouter_fin(unsigned int i)
{
	if(nb<taille)
	{
		tab[nb]=i;
		nb++;
	}
} 
Tableau Tableau::operator=( const Tableau& T)
{
	if(this!=&T)
	{
		delete[] tab;
		nb=T.nb;
		//cout<<"nb= "<<nb<<endl;
		taille=T.taille;
		tab= new long[T.taille];
	
	for (unsigned int i=0;i<nb;i++)
		{
			tab[i]=T.tab[i];
		}
	}
return *this;
}
Tableau Tableau::operator+(const Tableau& T)
{
	Tableau tump(taille+T.taille);
	for (unsigned int i=0;i<nb;i++)
	{
		tump.tab[i]=tab[i];
	}
	
	unsigned int i=nb;		
	for (unsigned int j=0;j<T.nb;j++)
	{
		tump.tab[i]=T.tab[j];
		i++;
	}
	tump.nb=nb+T.nb;			
	
return tump;	
}

bool Tableau::operator==(const Tableau& T)
{
	if(nb!=T.nb)
	{
		return false;
	}
	for(unsigned int i=0;i<nb;i++)
	{
		if(tab[i]!=T.tab[i])
		{
			return false;
		}
	}
	return true;
}

ostream& operator<<(ostream& out,const Tableau& T)
{
	for(unsigned int i=0;i<T.nb;i++)
	{
		out<<"tab de :"<<i<<"="<<T.tab[i]<<endl;
	}
return out;
}

void Tableau::supprimer(unsigned int i)
{
	if((i<nb)&&(i>0))
	{
		for(unsigned int j=i;j<nb-1;j++)
		{
			tab[j]=tab[j+1];
		}
		nb--;
	}

}

